package com.eifesun.monitor.application;

import java.util.Locale;
import java.util.ResourceBundle;

import com.eifesun.monitor.application.base.IResponse;

public enum DeviceType {

    INVERTER("INVERTER") {
        @Override
        public IResponse buildDeviceResponse(int functionCode) {
            return InverterResponse2.getType(functionCode);
        }
    },
    WEATHER("WEATHER") {
        @Override
        public IResponse buildDeviceResponse(int functionCode) {
            return WeatherResponse.getType(functionCode);
        }
    };

    private final String value;
    private static final String PROPERTY_PATH = "device_type";

    DeviceType(String value) {
        this.value = value;
    }

    public static DeviceType fromValue(String value) {

        if (value != null) {
            for (DeviceType device : values()) {
                if (device.toValue().equals(value)) {
                    return device;
                }
            }
        }

        throw new IllegalArgumentException("Invalid device: " + value);
    }

    public String toValue() {
        return value;
    }

    public String toDisplay(Locale locale) {
        return ResourceBundle.getBundle(PROPERTY_PATH, locale).getString(name().toLowerCase());
    }

    abstract public IResponse buildDeviceResponse(int functionCode);

}
